You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
24 lines
816 B
24 lines
816 B
import { deleteArticle, getArticleById } from "../../service/article";
|
|
import { requireUser, delCache } from "#server/utils/context";
|
|
|
|
export default defineWrappedResponseHandler(async (event) => {
|
|
await requireUser(event);
|
|
|
|
const idParam = getRouterParam(event, "id");
|
|
if (!idParam) return R.throwError(400, "缺少文章 ID", null);
|
|
const id = parseInt(idParam);
|
|
if (isNaN(id)) return R.throwError(400, "文章 ID 格式不正确", null);
|
|
|
|
const existing = await getArticleById(id);
|
|
if (!existing) return R.throwError(404, "文章不存在", null);
|
|
|
|
// Clear card caches for all associated cards before deleting
|
|
if (existing.cards.length > 0) {
|
|
await Promise.all(
|
|
existing.cards.map((c) => delCache(`card:${c.id}`)),
|
|
);
|
|
}
|
|
|
|
await deleteArticle(id);
|
|
return R.success(null);
|
|
});
|
|
|